public class Test {
    public static void main(String[] args) {
        //StringBuilder和StringBuffer功能类似
        StringBuilder stringBuilder = new StringBuilder();

        StringBuilder stringBuilder1 = new StringBuilder("666");
        //在原数据上进行修改，不会生成新的对象

        //String不可变，而StringBuilder和StringBuffer可变
        stringBuilder1.append(888);
        stringBuilder1.append("222");
        stringBuilder1.append(888).append(99.99);
        System.out.println(stringBuilder1);
        stringBuilder1.setCharAt(1, 'M');
        stringBuilder1.insert(1, "==");
        System.out.println(stringBuilder1);

        stringBuilder1.reverse();

        System.out.println(stringBuilder1);
        /**
         * String 和 StringBuilder并不能直接转换，要想转换：
         * 1.String 变 StringBuilder：利用StringBuilder构造方法 或 append方法
         *      构造方法：StringBuilder stringBuilder1 = new StringBuilder("666");
         * 2.StringBuilder 变 String：toString方法
         */
        String str = stringBuilder1.toString();
        System.out.println(str);
    }
    public static void main1(String[] args) {
        String s = "hello";
        //避免直接对String类型的对象进行修改，因为String的不可变性，所有的修改都会创建新对象，效率低
        s += " world";
        System.out.println(s);
    }
}
